package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;

import br.urca.dao.StatusProtocoloDAO;
import br.urca.model.Requerimento;
import br.urca.model.StatusProtocolo;

public class JPAStatusProtocoloDAO implements StatusProtocoloDAO {
	
	private final EntityManager manager;
	
	public JPAStatusProtocoloDAO() {
		this(null);
	}
	
	@Inject
	public JPAStatusProtocoloDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public StatusProtocolo getStatus(String codigo) {
		try {
			return this.manager
					.createQuery(
							"SELECT s FROM StatusProtocolo s "
									+ "WHERE s.codigo = :codigo ",
									StatusProtocolo.class).setParameter("codigo", codigo)
					.getSingleResult();
		} catch (Exception e) {
			return null;
		}	}

}
